﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ascx_user_language_setting : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!this.IsPostBack)
        {

            DatabaseUtil mydu = new DatabaseUtil();
            CookiesManager cookieMonster = new CookiesManager(Request, Response);
            ctpDataContext db=new ctpDataContext();

            

            string langcode = cookieMonster.getCookieValue(Citiport.Core.Const.COOKIE_USER_LANG);
            if (langcode == null)
            {
                langcode = "en";
            }
            else
            {
                langcode = langcode.Trim();
            }
            int langno = mydu.getLanguageNo(langcode);


            var data = from p in db.languages
                       where (p.no == 0 || p.no == 15 || p.no == 16) && p.language_no == langno
                       select new
                       {
                           title=p.title.Trim(),
                           code=p.code.Trim()

                       };

            this.DropDownList1.DataSource = data;
            this.DropDownList1.DataTextField = "title";
            this.DropDownList1.DataValueField = "code";

            this.CheckBoxList1.DataSource = data;
            this.CheckBoxList1.DataTextField = "title";
            this.CheckBoxList1.DataValueField = "code";

            this.DataBind();


            if (this.DropDownList1.Items.FindByValue(langcode) != null)
            {
                this.DropDownList1.Items.FindByValue(langcode).Selected = true;
            }



        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CookiesManager cookieMonster = new CookiesManager(Request, Response);
        cookieMonster.addCookie(Citiport.Core.Const.COOKIE_USER_LANG, this.DropDownList1.SelectedValue, DateTime.Now.AddYears(30));

        string url=Request.ServerVariables["url"]+"?"+Request.ServerVariables["query_string"];

        Response.Redirect(url);

    }
}
